Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] add submodule for C bindings, library compilation with PackageCompiler #88

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

m-fila
Copy link
Member

@m-fila m-fila commented Nov 11, 2024

Adding C bindings and ahead of time compilation to shared library with PackageCompiler.jl

C components have jetreconstruction_(or JETRECONSTRUCTION_) prefix

For now the C API includes only:

  • jet_reconstruct
  • exclusive_jets, inclusive_jets
  • enums and structs used in their signatures. When needed new structs with C-like layout are introduced (for instance replacing Vector{T} field with Ptr{T} and Csize_t fields for C-facing structs)

The C header file has to be written manually and keep in sync with Julia code. Technically the whole compile could be a separate julia package possibly eveb living in a separate repo, but I think it'd be harder to keep in sync this way


To do:

  • write to an output pointer from inclusive_jets and exclusive_jets
  • add error handling
  • support Lorentz vectors
  • add missing docstrings
  • add precompilation statements
  • cache all combinations of strategy and algorithm in procompilation
  • have actual test
  • install JetReconstructionConfig.cmake?
  • compilation with upcoming juliac?
    - [ ] add c-style building (make/CMake)?

Copy link

codecov bot commented Nov 11, 2024

Codecov Report

Attention: Patch coverage is 0% with 98 lines in your changes missing coverage. Please review.

Project coverage is 64.22%. Comparing base (eb8efd2) to head (44642d6).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/C_JetReconstruction/C_JetReconstruction.jl 0.00% 98 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (eb8efd2) and HEAD (44642d6). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (eb8efd2) HEAD (44642d6)
3 2
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #88      +/-   ##
==========================================
- Coverage   70.18%   64.22%   -5.97%     
==========================================
  Files          17       18       +1     
  Lines        1164     1258      +94     
==========================================
- Hits          817      808       -9     
- Misses        347      450     +103     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@m-fila m-fila changed the title add submodule for C bindings, library compilation with PackageCompiler [WIP] add submodule for C bindings, library compilation with PackageCompiler Nov 11, 2024
@m-fila
Copy link
Member Author

m-fila commented Nov 20, 2024

The CI for Julia 1.9 fails as documenting@ccallable functions was fixed only in 1.11 😢

I couldn't think of a good way of error handling.
What I propose here is to:

  • use status codes from enum with:
    • value for success,
    • values for each standard Julia exception,
    • single value for the remaining cases.
  • print the exception and backtrace to stderr so it's not lost

I also couldn't find a reasonable way to translate Julia exceptions to C++ exceptions without going through C-bottleneck

@Moelf
Copy link
Member

Moelf commented Nov 20, 2024

We don't need to support 1.9 I guess, but I hope we can backport JuliaLang/julia#51587 to 1.10.

@graeme-a-stewart
Copy link
Member

Yeah, I would agree we can drop support for 1.9 now, but the LTS release (1.10) we should try to support

@graeme-a-stewart
Copy link
Member

Just report this crashes on OS X with

[ Info: PackageCompiler: Executing /Users/graemes/.julia/dev/JetReconstruction/compile/precompile_execution.jl => /var/folders/kq/jgwv_wcj3ll2n6qwj06pp6jr0000gn/T/jl_packagecompiler_0hx01x/jl_dsyOUt
julia(84816,0x1f264cf40) malloc: *** error for object 0x134add910: pointer being freed was not allocated
julia(84816,0x1f264cf40) malloc: *** set a breakpoint in malloc_error_break to debug

[84816] signal 6: Abort trap: 6
in expression starting at /Users/graemes/.julia/dev/JetReconstruction/compile/precompile_execution.jl:33

I'm investigating!

@m-fila
Copy link
Member Author

m-fila commented Nov 21, 2024

Thanks for checking. I think that was because the results_ptrpointee was managed by Julia and got garbage collected. Should be fixed now

@graeme-a-stewart
Copy link
Member

Yes, now it works - thanks for the quick fix @m-fila!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants